﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.Adapters;
using System.Web;

namespace Mathoms.iSharePoint.MasterPages
{
	public class v4Custom : System.Web.UI.MasterPage
	{
        public v4Custom()
		{
			//Add our custom branding control adapter to brand the OOB web parts
			AddControlAdapterToType<Mathoms.iSharePoint.WebPartZoneAdapter>( typeof( Microsoft.SharePoint.WebPartPages.WebPartZone ) );
		}

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

		}

		private static void AddControlAdapterToType<T>( Type controlType ) where T : ControlAdapter, new()
		{
			if ( controlType == null )
			{
				throw new ArgumentNullException( "controlType", "This argument can not be null!" );
			}

			var adapters = HttpContext.Current.Request.Browser.Adapters;
			var key = controlType.AssemblyQualifiedName;
			if ( !adapters.Contains( key ) )
			{
				var adapter = typeof( T ).AssemblyQualifiedName;
				adapters.Add( key, adapter );
			}
		}
	}
}
